package yto.freemarker.grafana_prometheus_boot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import yto.freemarker.grafana_prometheus_boot.api.Result;


@SpringBootApplication
@Slf4j
public class GrafanaPrometheusBootApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(GrafanaPrometheusBootApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        int count = 0;
        while (true) {
            if (count / 2 == 0) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                RestTemplate restTemplate = new RestTemplate();
                ResponseEntity<Result> forEntity = restTemplate.getForEntity("http://localhost:8080/user/insert", Result.class);
            } catch (Exception e) {
                log.error(e.toString());
            }
        }
    }
}
